<html>
<head><meta charset="utf-8"><title>What is a binder? · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html">What is a binder?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201785086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201785086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201785086">(Jun 23 2020 at 21:21)</a>:</h4>
<p>So i've read the doc multiple times, but i don't really understand what a binder is.</p>



<a name="201785979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201785979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201785979">(Jun 23 2020 at 21:29)</a>:</h4>
<p>So, you can either have a <code>forall&lt;X&gt; ...</code> or <code>exists&lt;X&gt; ...</code></p>



<a name="201785989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201785989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201785989">(Jun 23 2020 at 21:29)</a>:</h4>
<p><code>X</code> in these cases are binders</p>



<a name="201786170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786170">(Jun 23 2020 at 21:30)</a>:</h4>
<p>In chalk, you might see something like <code>forall&lt;type&gt; exists&lt;type&gt; ^0.0: ^1.0</code></p>



<a name="201786173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786173">(Jun 23 2020 at 21:31)</a>:</h4>
<p>Its like, some kind of anonymous type? Probably is a terrible description but like "some type that we don't know yet what it is"?</p>



<a name="201786196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786196">(Jun 23 2020 at 21:31)</a>:</h4>
<p>Mmm, basically</p>



<a name="201786253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786253">(Jun 23 2020 at 21:31)</a>:</h4>
<p>more info: <a href="http://rust-lang.github.io/chalk/book/glossary.html?highlight=binder#binder">http://rust-lang.github.io/chalk/book/glossary.html?highlight=binder#binder</a></p>



<a name="201786337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786337">(Jun 23 2020 at 21:32)</a>:</h4>
<p>I've read that but the definition is the dev guide is slightly different i believe</p>



<a name="201786429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786429">(Jun 23 2020 at 21:33)</a>:</h4>
<p>how is it different?</p>



<a name="201786545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786545">(Jun 23 2020 at 21:34)</a>:</h4>
<div class="codehilite"><pre><span></span><code>Binder is a binder for higher-ranked lifetimes or types. It is part of the compiler&#39;s representation for things like for&lt;&#39;a&gt; Fn(&amp;&#39;a isize) (which would be represented by the type PolyTraitRef == Binder&lt;TraitRef&gt;)
</code></pre></div>



<a name="201786622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786622">(Jun 23 2020 at 21:35)</a>:</h4>
<p>I guess  what could help me understand is some diagrams to go from syntax -&gt; AST -&gt; HIR etc</p>



<a name="201786836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786836">(Jun 23 2020 at 21:37)</a>:</h4>
<p>I would say it's a place that introduces a new variable</p>



<a name="201786933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201786933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201786933">(Jun 23 2020 at 21:38)</a>:</h4>
<p>what exactly the variable means depends on the type of binder (forall or exists, or e.g. the variable representing the self type of a <code>dyn Trait</code>)</p>



<a name="201788515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201788515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201788515">(Jun 23 2020 at 21:51)</a>:</h4>
<p>Ok thanks</p>



<a name="201788530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201788530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201788530">(Jun 23 2020 at 21:51)</a>:</h4>
<p>Still need to think about it more.</p>



<a name="201834101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201834101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201834101">(Jun 24 2020 at 10:56)</a>:</h4>
<p>If you think about this piece of code</p>
<div class="codehilite"><pre><span></span><code><span class="o">|</span><span class="n">x</span>: <span class="kt">u32</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p><code>x</code> doesn't mean anything in the body of the closure without the preceeding <code>|x: u32|</code>. We say that <code>|x: u32|</code> <em>binds</em>  <code>x</code> in the body. The same idea exists for types!</p>
<p><code>Foo&lt;X&gt;</code> doesn't mean anything unless <code>X</code> is somehow <em>bound</em>. <code>forall&lt;X&gt;</code> and <code>exists&lt;X&gt;</code> introduce <code>'a</code> in the same way as <code>|x: u32|</code> introduced <code>x</code>.</p>



<a name="201835576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201835576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201835576">(Jun 24 2020 at 11:17)</a>:</h4>
<p>Thank you! You meant <code>introduce X</code> instead of <code>'a</code> right?</p>



<a name="201844805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/What%20is%20a%20binder%3F/near/201844805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nathan Corbyn <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/What.20is.20a.20binder.3F.html#201844805">(Jun 24 2020 at 13:10)</a>:</h4>
<p>Yeah sorry about that hahaha</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>